
function initJsontable(jsonlist){
	clearJsontable();
	if(jsonlist==null)return;
		for(var i =0;i<jsonlist.length;i++){
				var object = jsonlist[i];
				var jsonTr = document.getElementById(jsonPage_jsonTr);
					if(i==0){
						jsonTr.style.display="";
						newTr = initJsontr(jsonTr,object,i);
		 				if(jsonTr.firstChild.firstChild.val == "SERIALNUMBER") 
						jsonTr.firstChild.firstChild.value =1;
					}else{
						newTr = jsonTr.cloneNode(1);
						newTr = initJsontr(newTr,object);
						newTr.style.display="";
						if(newTr.firstChild.firstChild.val == "SERIALNUMBER") 
						newTr.firstChild.firstChild.value = i+1;
						jsonTr.parentNode.appendChild(newTr);
					}
		}
}
function doPrint(){
	if(jsonPage_sql==""){
	alert("请先进行查询操作");
	return;
	}

	var thisJsp 		= 	window.location.pathname;
	var jsps = thisJsp.split("/");
	thisJsp = jsps[jsps.length-1];
	 
	thisJsp 			= 	thisJsp.slice(0,thisJsp.length-4)+"_Print.jsp";
	form 				= 	document.forms[0];
	var url = 	thisJsp+"?sql="+encodeURIComponent(jsonPage_sql);
	location.href = url;
}
function initJsontr(initTr,objects,row){
	var	tds = initTr.childNodes;
		for(var x=0;x<tds.length;x++){
		    var inputs = tds[x].childNodes;
				for(var k=0;k<inputs.length;k++){
					//alert(inputs[k].type)
					if(inputs[k].type&&inputs[k].val&&inputs[k].val!=""){
						if(inputs[k].tagName=="SELECT"&&inputs[k].vals=="sels"){
							inputs[k].options[0] = new Option('请选择','请选择');
							inputs[k].options[1] = new Option(eval('objects.'+inputs[k].val),eval('objects.'+inputs[k].val));
						}
						inputs[k].value = eval('objects.'+inputs[k].val);
						inputs[k].title = eval('objects.'+inputs[k].val);
						if(inputs[k].value=="null"||inputs[k].val=="ins"){
							inputs[k].value ="";
							inputs[k].title ="";
						}
						if(inputs[k].read||inputs[k].val=="ins"){
							inputs[k].readOnly=false;
						}
						if(inputs[k].val=="but"){
							if(row!=0) inputs[k].value=" 删除 ";
							else inputs[k].value=" 添加 ";
						}
					}
				}
		}
	return initTr;
}

function clearJsontable(){

	var jsonTrs = document.getElementById(jsonPage_jsonTr);
	var trs = jsonTrs.parentNode.childNodes;
	var len = trs.length;
	for(var x =len-1;x>0;x--){
		var jsonTr = trs[x];
		if(trs.length>jsonPage_together) jsonTr.parentNode.removeChild(jsonTr);
	}
	for(var i = 0;i<jsonTr.childNodes.length;i++){
		if(jsonTr.childNodes[i].firstChild.type=="text"){
			jsonTr.childNodes[i].firstChild.value=""
		}else if(jsonTr.childNodes[i].firstChild.type=="checkbox"){
			jsonTr.childNodes[i].firstChild.checked=false;
		}
	}
	if(jsonTr)
	jsonTr.style.display="none";
}
////========================================================================
var project = "/pressystem";
var jsonPage_paging 		= "paging";
var jsonPage_jsonTr 		= "jsonTr";
var jsonPage_thisCount		= "1";
var jsonPage_lineCount		= "10";
var jsonPage_action			= 'first';
var jsonPage_first			= project+'/parts/images/first.gif';
var jsonPage_end			= project+'/parts/images/end.gif';
var jsonPage_previousPic	= project+'/parts/images/previous.gif';
var jsonPage_nextPic		= project+'/parts/images/next.gif';
//选择哪个sql
var jsonPage_sql			= '';
//where条件	
var jsonPage_where			= '';
//显示结果表中 默认有2条tr
var jsonPage_together		= 2;
//列名
var jsonPage_commons		= '';
//是否拼语句 true为拼写
var jsonPage_boolean		= 'false';
//设置查询模式
var jsonPage_state 			= "hql";
function doPaging(){
	var initMap ={
	//翻页图片
	'previousPic':jsonPage_previousPic,
	'nextPic':jsonPage_nextPic,
	'first':jsonPage_first,
	'end':jsonPage_end,
	//当前页数
	'thisCount':jsonPage_thisCount,
	//每页显示行数
	'lineCount':jsonPage_lineCount,
	'sql':jsonPage_sql,
	'where':jsonPage_where,
	'action':jsonPage_action,
	'commons':jsonPage_commons,
	'blon':jsonPage_boolean,
	'state':jsonPage_state
	}
	DWREngine.setAsync(false);
	ajax.jsonPaging(initMap,function(pageObject){
		try{
			var pagingDiv = document.getElementById(jsonPage_paging);
			pagingDiv.innerHTML=pageObject.pagediv;
		}catch(e){
			var pagingDivhide = document.getElementById("pagedivhide");
			pagingDivhide.innerHTML=pageObject.pagedivhide;
		}
			initJsontable(pageObject.pagelist);
			on_Jsonpaging_Back();
	});
}

function doPagingExt(){
	var initMap ={
	//上一页图片
	'previousPic':jsonPage_previousPic,
	'nextPic':jsonPage_nextPic,
	'first':jsonPage_first,
	'end':jsonPage_end,
	//当前页数
	'thisCount':jsonPage_thisCount,
	//每页显示行数
	'lineCount':jsonPage_lineCount,
	'sql':jsonPage_sql,
	'where':jsonPage_where,
	'action':jsonPage_action,
	'commons':jsonPage_commons,
	'blon':jsonPage_boolean,
	'state':jsonPage_state
	}
	DWREngine.setAsync(false);
	ajax.jsonPaging(initMap,function(pageObject){
		try{
			var pagingDiv = document.getElementById(jsonPage_paging);
			pagingDiv.innerHTML=pageObject.pagediv;
		}catch(e){}
			var list = cleanData(pageObject.pagelist,jsonPage_commons);
			Ext.grid.jsonData=list;
			if(store!=null){
				store.loadData(Ext.grid.jsonData);
			}else{
				//on_Jsonpaging_Back();
				setTimeout('initGrid()',50);
			}
	});
}

function on_Jsonpaging_Back(){

}

function cleanData(data,common){
	if(data!=null && common != null){
		var list = [];
		//分解标识字符串
		var com = common.split(',');
		for(var i = 0 ; i < data.length ;i ++){ 
			var subList = [] ;
			for(var j = 0 ; j < com.length ; j ++){
				//如果标识当前元素不为空				
				if(com[j] != null && com[j] != ""){
					var vs=eval('data[i].'+com[j]);
					//循环将List中map元素取出放入subList中
					subList[j] = vs;
				}
			}
			//将subList放入List中形成二位数组
			list[i] = subList ;				 
	 	}
		return list;
	}
}

function on_Jsonpaging_IndexPage(){
	if(document.forms[0].jsonPage_page){
		jsonPage_thisCount = document.forms[0].jsonPage_page.value;
	}
jsonPage_action = "index";
doPaging();
}

function on_Jsonpaging_PreviousPage(){
	if(document.forms[0].jsonPage_page){
		jsonPage_thisCount = document.forms[0].jsonPage_page.value;
	}
	jsonPage_action = "previous";
	doPaging();
}

function on_Jsonpaging_NextPage(){
	if(document.forms[0].jsonPage_page){
		jsonPage_thisCount = document.forms[0].jsonPage_page.value;
	}
jsonPage_action = "next";
doPaging();
}

function on_Jsonpaging_FirstEnd(net){
jsonPage_thisCount = net;
jsonPage_action = "index";
doPaging();
}
